﻿@using BlazorBlogs.Data;
@using BlazorBlogs.Data.Models;
@inherits OwningComponentBase<GeneralSettingsService>
<div class="top-row pl-4 navbar navbar-dark">
    <a class="navbar-brand" href="">
        @if (objGeneralSettings != null)
        {
            <img src="@objGeneralSettings.ApplicationLogo" />
        }
    </a>
    <button class="navbar-toggler" @onclick="ToggleNavMenu">
        <span class="navbar-toggler-icon"></span>
    </button>
</div>

<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
    <ul class="nav flex-column">
        <li class="nav-item px-3">
            <NavLink class="nav-link" href="" Match="NavLinkMatch.All">
                <span class="oi oi-home" aria-hidden="true"></span> Home
            </NavLink>
            <NavLink class="nav-link" href="filedownloads" Match="NavLinkMatch.All">
                <span class="oi oi-cloud-download" aria-hidden="true"></span> Downloads
            </NavLink>
        </li>
        <AuthorizeView>
            <Authorized>
                @if (@context.User.IsInRole(ADMINISTRATION_ROLE))
                {
                    <li class="nav-item px-3">
                        <NavLink class="nav-link" href="administration">
                            <span class="oi oi-person" aria-hidden="true"></span> User Administration
                        </NavLink>
                    </li>
                    <li class="nav-item px-3">
                        <NavLink class="nav-link" href="categories">
                            <span class="oi oi-list-rich" aria-hidden="true"></span> Category Administration
                        </NavLink>
                    </li>
                    <li class="nav-item px-3">
                        <NavLink class="nav-link" href="filemanager">
                            <span class="oi oi-folder" aria-hidden="true"></span> File Manager
                        </NavLink>
                    </li>
                    <li class="nav-item px-3">
                        <NavLink class="nav-link" href="importblogs">
                            <span class="oi oi-cloud-upload" aria-hidden="true"></span> Import Blogs
                        </NavLink>
                    </li>
                    <li class="nav-item px-3">
                        <NavLink class="nav-link" href="logs">
                            <span class="oi oi-book" aria-hidden="true"></span> Logs
                        </NavLink>
                    </li>
                    <li class="nav-item px-3">
                        <NavLink class="nav-link" href="settings">
                            <span class="oi oi-cog" aria-hidden="true"></span> Settings
                        </NavLink>
                    </li>
                }
                <li class="nav-item px-3">
                    <form method="post" action="Identity/Account/LogOut">
                        <button type="submit" class="btn btn-link">
                            <span style="color:white"> [Logout]</span>
                        </button>
                    </form>
                </li>
            </Authorized>
            <NotAuthorized>
                <li class="nav-item px-3">
                    <NavLink class="nav-link" href="Identity/Account/Login">
                        <span class="oi oi-list-rich" aria-hidden="true"></span> [Login]
                    </NavLink>
                </li>
                @if (AllowRegistration)
                {
                    <li class="nav-item px-3">
                        <NavLink class="nav-link" href="Identity/Account/Register">
                            <span class="oi oi-list-rich" aria-hidden="true"></span> [Register]
                        </NavLink>
                    </li>
                }
            </NotAuthorized>
        </AuthorizeView>
    </ul>
</div>

@code {
    GeneralSettings objGeneralSettings;
    string ADMINISTRATION_ROLE = "Administrators";
    bool collapseNavMenu = true;
    bool AllowRegistration = false;

    string NavMenuCssClass => collapseNavMenu ? "collapse" : null;

    protected override async Task OnInitializedAsync()
    {
        objGeneralSettings = await @Service.GetGeneralSettingsAsync();
        AllowRegistration = objGeneralSettings.AllowRegistration;
    }

    void ToggleNavMenu()
    {
        collapseNavMenu = !collapseNavMenu;
    }
}